package dd.control;

import org.w3c.dom.NamedNodeMap;

import xml.Message;
import dd.model.Event;
import dd.model.Model;
import dd.view.ResultScreen;

/**
 * Open the result screen as soon as receive the open message
 */
public class ReportResponseController {

	public void process(Message response) {
		// this response is processed by result screen
		NamedNodeMap map = response.contents.getFirstChild().getFirstChild().getAttributes();
		boolean iscomplete = map.getNamedItem("completed").getNodeValue().equals("completed") ? true : false;

		Event event = Model.getInstance().getEvent();
		event.setcomplete(iscomplete);

		// show the open response window
		if (Model.getInstance().getResultScreen() == null) {
			ResultScreen resultScreen = new ResultScreen(event);
			resultScreen.setVisible(true);
			Model.getInstance().setResultScreen(resultScreen);
		} else {
			ResultScreen resultScreen = new ResultScreen(event);
			resultScreen.setVisible(true);
			Model.getInstance().getResultScreen().dispose();
			Model.getInstance().setResultScreen(resultScreen);
		}

		// get the add edge frame from the model and then dispose it
		if (Model.getInstance().getaef() != null) {
			// Model.getInstance().getaef().dispose();
		}
	}
}
